package net.osweb.core.tools.utils.crm;

import java.util.Calendar;
import java.util.Date;

public class CalUtil {
	private CalUtil(){}
	
	/**
	 * @return 过期时间：一天
	 */
	public static Date getExpiryDay(){
		return getExpiryDay(1);
	}
	
	/**
	 * @param day
	 * @return 过期时间(单位：天)
	 */
	public static Date getExpiryDay(int day){
		Calendar expiry = Calendar.getInstance();
		expiry.setTime(new Date());	
		expiry.add(Calendar.DATE, day);
		
		return expiry.getTime();
	}

	/**
	 * @return 过期时间：一小时
	 */
	public static Date getExpiryHour(){
		return getExpiryHour(1);
	}	
	/**
	 * @param day
	 * @return 过期时间(单位：小时)
	 */
	public static Date getExpiryHour(int hour){
		Calendar expiry = Calendar.getInstance();
		expiry.setTime(new Date());	
		expiry.add(Calendar.HOUR, hour);
		
		return expiry.getTime();
	}	
	
	/**
	 * @return 过期时间：一分钟
	 */
	public static Date getExpiryMinute(){
		Calendar expiry = Calendar.getInstance();
		expiry.setTime(new Date());	
		expiry.add(Calendar.MINUTE, 1);
		
		return expiry.getTime();		
	}
	/**
	 * @param day
	 * @return 过期时间(单位：分钟)
	 */
	public static Date getExpiryMinute(int minute){
		Calendar expiry = Calendar.getInstance();
		expiry.setTime(new Date());	
		expiry.add(Calendar.MINUTE, minute);
		
		return expiry.getTime();		
	}
	
	
	/**
	 * @return 过期时间：一秒钟
	 */
	public static Date getExpirySecond(){
		Calendar expiry = Calendar.getInstance();
		expiry.setTime(new Date());	
		expiry.add(Calendar.SECOND, 1);
		
		return expiry.getTime();		
	}
	/**
	 * @param second
	 * @return 过期时间(单位：秒)
	 */
	public static Date getExpirySecond(int second){
		Calendar expiry = Calendar.getInstance();
		expiry.setTime(new Date());	
		expiry.add(Calendar.SECOND, second);
		
		return expiry.getTime();		
	}
	
	
	
	public static Date getFirstDayOfWeek(){
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.SUNDAY);
	    c.setTime(new Date());
	    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); 
	    c.set(Calendar.HOUR_OF_DAY,0);
	    c.set(Calendar.MINUTE,0);
	    c.set(Calendar.SECOND,0);
	    return c.getTime();
	}
	public static Date getLastDayOfWeek(){
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.SUNDAY);
	    c.setTime(new Date());
	    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()+6); 
	    c.set(Calendar.HOUR_OF_DAY,23);
	    c.set(Calendar.MINUTE,59);
	    c.set(Calendar.SECOND,59);	    
	    return c.getTime();
	}
	
	
	public static void main(String[] args) {
		System.out.println(getFirstDayOfWeek());
		System.out.println(getLastDayOfWeek());
	}
	
	
}
